<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout}">

<head>
    <title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE"
           th:text="${notice.id != null} ? '编辑通知' : '新增通知'"></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light">
<div layout:fragment="content">
    <div class="card">
        <div class="card-header">
            <h2 th:text="${notice.id != null} ? '编辑通知内容' : '创建新通知'"></h2>
        </div>
        <div class="card-body">
            <form th:action="@{/api/notices/save}" th:object="${notice}" method="post">
                <input type="hidden" th:field="*{id}"/>
                <input type="hidden" th:field="*{createTime}"/>

                <div class="mb-3">
                    <label class="form-label">通知标题</label>
                    <input type="text" class="form-control" th:field="*{title}" required
                           placeholder="请输入通知标题" maxlength="50">
                </div>

                <div class="mb-3">
                    <label class="form-label">通知内容</label>
                    <textarea class="form-control" th:field="*{content}" rows="6" required
                              placeholder="请输入通知详细内容"></textarea>
                </div>

                <div class="mb-3" th:if="${notice.id != null}">
                    <label class="form-label">发布时间</label>
                    <input type="text" class="form-control"
                           th:value="${#temporals.format(notice.createTime, 'yyyy-MM-dd HH:mm:ss')}"
                           readonly>
                </div>

                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                    <button type="submit" class="btn btn-primary">保存通知</button>
                </div>
            </form>
            <div class="d-grid gap-2 d-md-flex justify-content-md-end mt-2">
                <form th:action="@{/api/notices}" method="get">
                    <button type="submit" class="btn btn-outline-secondary">返回列表</button>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>